<template>
  <div>
    <z-table ref="table" rowKey="id" :showAlert="false" :showSelection="false" :loading="loading" :columns="columns"
      :dataSource="pageData" @change="onTableChange">
      <template slot="evlNum" slot-scope="text">
        <span>第 {{ text }} 次</span>
      </template>
      <template slot="assessmentTime" slot-scope="text, record">
        <span>{{ record.assessmentStartTime }} ~ {{ record.assessmentEndTime }}</span>
      </template>
      <template slot="plannedTime" slot-scope="text, record">
        <span>{{ record.plannedStartTime }} ~ {{ record.plannedEndTime }}</span>
      </template>
      <template slot="assessmentStatus" slot-scope="text,record">
        <span v-if="text == '0'" style="color:#999">待开始</span>
        <span v-if="text == '1'" style="color:#108EE9">待审批</span>
        <span v-if="text == '2'" style="color:#FAAD14">审批中</span>
        <span v-if="text == '3'" style="color:#000">完成</span>
        <span v-if="text == '4'" style="color:#000">驳回</span>
        <span v-if="text == '9' && record.entryStatus == '2'" style="color:#27BF44">待录入</span>
        <span v-if="text != '10' && record.entryStatus == '1'" style="color:#D9001B">已逾期 <a-tag color="red"
            v-if="record.overdueResponsibilityName">
            {{ record.overdueResponsibilityName }}
          </a-tag></span>
        <span v-if="text == '10'" style="color:#FAAD14">补录申请中</span>
      </template>
      <!--操作-->
      <template slot="action" slot-scope="text, record">
        <template v-if="record.assessmentStatus == '9' && record.entryStatus == '2'">
          <a-button @click="onInput(1, record)" type="link" style="padding: 0">添加评估</a-button>
          <a-divider type="vertical" />
        </template>
        <template
          v-if="record.assessmentStatus == '1' || record.assessmentStatus == '2' || record.assessmentStatus == '10'">
          <a-button @click="onCX(record)" type="link" style="padding: 0">撤销申请</a-button>
          <a-divider type="vertical" />
          <a-button @click="onCYX(record)" type="link" style="padding: 0">催一下</a-button>
          <a-divider type="vertical" />
          <a-button @click="onDetail(record)" type="link" style="padding: 0">查看</a-button>
        </template>
        <template v-if="record.entryStatus == '1' && record.assessmentStatus != '10'">
          <a-button @click="onInput(2, record)" type="link" style="padding: 0">评估补录</a-button>
        </template>
      </template>
    </z-table>
    <!--    <AddModal ref="addModalId" :pTitle="pTitle" @ok="onQuery" />-->
  </div>
</template>
<script>
import * as totalEstimate from '@/api/sjsk/help/totalEstimate.js'
import { undoApply } from '@/api/sjsk/check/uroscopy.js'
// import AddModal from './AddModal'
import { getUrge } from '@/api/sjsk/flowService'
export default {
  components: {
    // AddModal,
  },
  data() {
    return {
      loading: false,
      columns: [
        {
          title: '序号',
          dataIndex: 'order',
          width: 60,
          align: 'center',
          customRender: (text, record, index) =>
            `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
        },
        {
          title: '评估次数',
          dataIndex: 'evlNum',
          align: 'center',
          scopedSlots: { customRender: 'evlNum' },
        },
        {
          title: '评估时段',
          dataIndex: 'assessmentTime',
          align: 'center',
          scopedSlots: { customRender: 'assessmentTime' },
        },
        {
          title: '计划时间',
          dataIndex: 'plannedTime',
          align: 'center',
          scopedSlots: { customRender: 'plannedTime' }
        },
        {
          title: '录入状态',
          dataIndex: 'assessmentStatus',
          align: 'center',
          scopedSlots: { customRender: 'assessmentStatus' },
        },
        {
          title: '评估时间',
          dataIndex: 'createTime',
          align: 'center',
        },
        {
          title: '操作',
          width: 250,
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      pageFilter: {
        pageNo: 1,
        pageSize: 10,
      },
      personId: '1',
      assessmentType: 1, //评估类型，1为季度评估，2为年度评估
      pageData: [],
      alertInfo: "",
      pTitle: "添加季度评估"
    }
  },
  created() {
    // this.onQuery()
  },
  methods: {
    onQuery() {
      this.refreshTable()
    },
    onTableChange(pagination, pageFilter, sorter) {
      let keyMap = { currentPage: 'pageNo' }
      let paginations = Object.keys(pagination).reduce((newData, key) => {
        let newKey = keyMap[key] || key
        newData[newKey] = pagination[key]
        return newData
      }, {})
      this.pageFilter = Object.assign({}, this.pageFilter, paginations)
      this.refreshTable()
    },
    refreshTable() {
      this.loading = true
      let params = Object.assign({}, { id: this.personId, type: this.assessmentType })
      totalEstimate.viewCompEvaluationHistory(params).then((res) => {
        if (res.success) {
          this.alertInfo = res.result.time
          this.pageData = res.result.viewCompEvaluationHistoryVOS
          this.loading = false
        } else {
          this.loading = false
        }
      })
        .catch((e) => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
    },
    setType(type) {
      this.assessmentType = type
    },
    onInput(type, record) {
      if (this.assessmentType == '1') {
        this.pTitle = "添加季度评估"
      } else {
        this.pTitle = "添加年度评估"
      }
      // this.$refs.addModalId.show(type, record)
    },
    onHistory(record) {
      this.$router.push({
        path: "/totalEstimate/record",
        query: {
          sjskPersonId: record.sjskPersonId
        }
      })
    },
    //跳到审批详情
    onDetail(record) {
      let flowType = ""
      if (this.assessmentType == '1') {
        flowType = "26" //季度评估审批
      } else {
        flowType = "27" //年度评估审批
      }
      this.$router.push({
        path: `/examine/details/` + flowType + `/${record.id}`
      })
    },
    onCYX(record) {
      getUrge({ taskId: record.id, taskType: '19' }).then((res) => { //取消常规尿液检测审批
        if (res.success) {
          this.$message.success(res.message);
          this.onQuery()
        } else {
          this.$message.warning(res.message);
        }
      });
    },
    onCX(record) {
      let that = this;
      let flowType = ""
      if (this.assessmentType == '1') {
        flowType = "26" //季度评估审批
      } else {
        flowType = "27" //年度评估审批
      }
      // if (record.type == 1) flowType = "26" //季度评估审批
      // if (record.type == 2) flowType = "27" //年度评估审批
      // if (record.type == 3) flowType = "28" //季度评估补录审批
      // if (record.type == 4) flowType = "29" //年度评估补录审批
      this.$confirm({
        title: `还在审批中，确定要撤销吗?`,
        okText: "确认",
        okType: "danger",
        cancelText: "取消",
        onOk() {
          undoApply({ taskId: record.id, type: flowType }).then((res) => { //取消定期访谈审批，审批流程类型24
            if (res.success) {
              that.$message.success(res.message);
              that.onQuery()
            } else {
              that.$message.warning(res.message);
            }
          });
        }
      });
    },
  },
}
</script>
<style lang="less" scoped>

</style>
